package m.jclecai.com.fragment.klpk;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


import com.squareup.okhttp.Request;
import com.viewpagerindicator.CirclePageIndicator;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import m.jclecai.com.R;
import m.jclecai.com.bean.klpk.bean.PokerBettingBean;
import m.jclecai.com.constant.Constant_Url;
import m.jclecai.com.fragment.klpk.pager.BasePagerFragment;
import m.jclecai.com.fragment.klpk.pager.FlushFragment;
import m.jclecai.com.fragment.klpk.pager.OptionalFragment;
import m.jclecai.com.fragment.klpk.pager.PairFragment;
import m.jclecai.com.fragment.klpk.pager.SameColorFragment;
import m.jclecai.com.fragment.klpk.pager.StraightFlushFragment;
import m.jclecai.com.fragment.klpk.pager.ThreeSheetsFragment;
import m.jclecai.com.utils.BaseUtils;
import m.jclecai.com.utils.KlpkUtils;
import m.jclecai.com.utils.http.HttpManager;
import m.jclecai.com.view.common.BottomBar;
import q.rorbin.badgeview.Badge;


/**
 * Created by andy on 2017/6/6.
 * <p>
 * 这里面我们的逻辑是将ViewPager放到这里来；
 *
 * 这里我们要做的一个机制就是修改一下ViewPager的加载机制；
 */
public class PokerFragment extends Fragment implements View.OnClickListener {

    private ViewPager mViewPager;
    private MyPagerAdapter mMyPagerAdapter;
    private CirclePageIndicator mPageIndicator;
    private TextView mTvRules;

    private View mLlNoRadioRules;
    private View mLlRules;
    private TextView mTvRulesNoBtn;

    public View bottomView;

    private View mLlBottomTitle;
    private TextView mTvBettingNumber;
    private TextView mTvProfit;


    private List<PokerBettingBean> mData=new ArrayList<>();
    private Badge mBadge;

    //当前选中页的Fragment对象；
    private BasePagerFragment mCurrentPagerFragment;
    private int mTotalBettingNum;
    private BottomBar mBottomBar;

    //这里是Activity底部的那个布局的View；
    public void setBottomView(View bottomView) {
        this.bottomView = bottomView;

        mBottomBar = ((BottomBar) bottomView.findViewById(R.id.bottom_bar));

        mBottomBar.setRightButtonClickListener(this);

        mLlBottomTitle = bottomView.findViewById(R.id.ll_bottom_title);
        mTvBettingNumber = ((TextView) bottomView.findViewById(R.id.tv_betting_number));
        mTvProfit = ((TextView) bottomView.findViewById(R.id.tv_profit));

    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_poker, container, false);

        mViewPager = ((ViewPager) view.findViewById(R.id.view_pager));
        mPageIndicator = ((CirclePageIndicator) view.findViewById(R.id.indicator));

        mTvRules = ((TextView) view.findViewById(R.id.rule_des));

        //这里表示是否规则的LinearLayout
        mLlNoRadioRules = view.findViewById(R.id.ll_no_radio_rules);
        mLlRules = view.findViewById(R.id.ll_with_radio_rules);

        mTvRulesNoBtn = ((TextView) view.findViewById(R.id.rule_des_no_button));


        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        //这里我们将相应的Fragment添加进来
        if (mViewPager != null) {
            mMyPagerAdapter = new MyPagerAdapter(getChildFragmentManager());
            PairFragment pairFragment = new PairFragment();
            SameColorFragment sameColorFragment = new SameColorFragment();
            FlushFragment flushFragment = new FlushFragment();
            StraightFlushFragment straightFlushFragment = new StraightFlushFragment();
            ThreeSheetsFragment threeSheetsFragment = new ThreeSheetsFragment();
            OptionalFragment optionalFragment = new OptionalFragment();

           // mViewPager.setOffscreenPageLimit(6);
            System.out.println("offscreenPageLimitCount:"+mViewPager.getOffscreenPageLimit());
            //添加5个Fragment;
            mMyPagerAdapter.addItem(pairFragment);
            mMyPagerAdapter.addItem(sameColorFragment);
            mMyPagerAdapter.addItem(flushFragment);
            mMyPagerAdapter.addItem(straightFlushFragment);
            mMyPagerAdapter.addItem(threeSheetsFragment);
            mMyPagerAdapter.addItem(optionalFragment);

            mViewPager.setAdapter(mMyPagerAdapter);
            mPageIndicator.setViewPager(mViewPager);

            for (final BasePagerFragment pagerFragment : mMyPagerAdapter.getData()) {

                pagerFragment.setOnCheckedChangeListener(new BasePagerFragment.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChangeListener() {
                        refreshBottom();
                    }
                });
            }
            //初始化数据
            mViewPager.setCurrentItem(0);
            //mViewPager.setOffscreenPageLimit(6);
            changeRules(0);
            mCurrentPagerFragment=mMyPagerAdapter.getData().get(0);

            mPageIndicator.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
                @Override
                public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

                }

                @Override
                public void onPageSelected(int position) {

                }

                @Override
                public void onPageScrollStateChanged(int state) {

                }
            });

            mBottomBar.setLeftButtonClickListener(this);

            mBottomBar.setCenterButtonClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    KlpkUtils.showText(getActivity(),"至少选择一注");
                }
            });
            mBottomBar.setOnDragstateChangeListener(new Badge.OnDragStateChangedListener() {
                @Override
                public void onDragStateChanged(int dragState, Badge badge, View targetView) {
                    /**
                     *dragState：start,1表示开始，
                     * 2,表示在范围内拖动，
                     * 3、表示在范围外拖动；
                     * 4、回去了
                     * 5、表示成功了
                     */
                    if(dragState==Badge.OnDragStateChangedListener.STATE_SUCCEED){
                        mTotalBettingNum=0;
                        mData.clear();
                    }
                }
            });

            //这里的话，我们是需要请求网络获取遗漏信息的；
            requestMissData();
        }
    }

    public void requestMissData() {
        //请求网络获取遗漏信息；
        HttpManager.getAsyn(Constant_Url.KLPK_MISSING_DATA, new HttpManager.StringCallback() {
            @Override
            public void onFailure(Request request, IOException e) {

            }

            @Override
            public void onResponse(String response) {
                //这里我们得到字符串数据，将其解析成对应的遗漏；

                try {
                    //这里我们对其进行一个解析，是可能出现问题的；
                    setMissData(response);

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    private void refreshBottom() {
        //这里我们要执行的逻辑就是；
        if (!mCurrentPagerFragment.hasChecked()) {
            //没有被选中的，我们啥事都不做
            mLlBottomTitle.setVisibility(View.INVISIBLE);
            mBottomBar.setLeftButtonText("机选");

            //投注区要改变；

            mBottomBar.setChecked(false);

            mBottomBar.setCenterButtonClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //这里我们是需要将其，
                    KlpkUtils.showText(getActivity(),"至少选择一注");
                }
            });
        } else {
            //有一些被选中了，我们要做的一个逻辑就是
            //1、bottom_title,机选，投注区

            mBottomBar.setLeftButtonText("清空");
            //这里话，投注区要改变；
            //这里我们是需要修改mIvBettingArea的点击事件；//// TODO: 2017/6/10
            List<Integer> selectedItemIndexs = mCurrentPagerFragment.getSelectedItemIndexs();
            int hasSelectedSize= mCurrentPagerFragment.hasSelectAllChecked()?selectedItemIndexs.size
                    ()+1:selectedItemIndexs.size();

            if(mCurrentPagerFragment.canBetting(hasSelectedSize)){
                mLlBottomTitle.setVisibility(View.VISIBLE);
              //  mIvBettingArea.setChecked(true);
                mBottomBar.setChecked(true);
                changeBottomTitle();
                //mIvBettingArea是可以点击的添加到投注区的；
                mBottomBar.setCenterButtonClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //这里我们将进行一个操作做就是，将选中的条目添加到，内存中；
                        addBetting();
                    }
                });
            }
        }
    }



    /**
     * 这里我们进行一个的操作就是将所选的条目添加到投注区；
     */
    private void addBetting() {

        PokerBettingBean pokerBettingBean = new PokerBettingBean();

        //这里我们将用户选择的东西进行一个保存；
        int index = mCurrentPagerFragment.getIndex(); //种类；
        pokerBettingBean.setIndex(index);

        List<Integer> selectedList = new ArrayList<>();
        if(index<5){
            List<Integer> selectedItemIndexs = mCurrentPagerFragment.getSelectedItemIndexs();  //选择的条目；//获取包选；

            for (Integer selectedItemIndex : selectedItemIndexs) {
                selectedList.add(selectedItemIndex+1);
            }
            if (mCurrentPagerFragment.hasSelectAllChecked()) {
                selectedList.add(0);
            }
        }else{
            selectedList=mCurrentPagerFragment.getSelectedItemIndexs();
        }


        pokerBettingBean.setDatas(selectedList);
        pokerBettingBean.setBettingNumber(getBettingNumber(mCurrentPagerFragment) ); //这里是当前的注数

        mTotalBettingNum+=getBettingNumber(mCurrentPagerFragment);  //这里是总共的注数；
        mData.add(pokerBettingBean);

        mBottomBar.setBettingNumber(mTotalBettingNum);
        mCurrentPagerFragment.clear();

        //这里的话，是对我们的代码的一个验证：这里打印正确，说明是没有问题的；
        for (PokerBettingBean bettingBean : mData) {
            List<Integer> datas = bettingBean.getDatas();
            int typeIndex=bettingBean.getIndex()<5?bettingBean.getIndex():5;
            for (Integer data : datas) {
                System.out.println("投注区： "+ KlpkUtils.indexType[bettingBean.getIndex()]+"牌："+ KlpkUtils.pokerType
                        [typeIndex][data]);
            }
        }
    }

    /**
     * 只要进来这个方法表示BasePagerFragment里面必然有选中的：要么是item，要么是包选；
     * ,通过知道PagerFragment里面的一些参数来计算显示相应的cost，itemAward,profit
     *
     */
    private void changeBottomTitle() {
        //这里面，我们title的变化，由两个因素决定1、item的选中状态，2、是否有包选按钮；
        int size = mCurrentPagerFragment.getSelectedItemIndexs().size();
        int index = mCurrentPagerFragment.getIndex();
        //条目被选中的奖金
        int itemAward = mCurrentPagerFragment.getItemAward();
        //包选被选中的时候，奖金
        int selectAllAward = mCurrentPagerFragment.getSelectAllAward();
        //这里表示每注多少钱；
        int everyBetting = 2;
        int cost = 0;
        int profit = 0;
        //可能会存在一个范围，奖金的一个范围；
        int startAward = 0;
        int endAward = 0;
        int startProfit = 0;
        int endProfit = 0;

        String strBettingNumber = "";
        String strProfit = "";
        int bettingNumber=0;



        if (index >= 0 && index < 5) {

            bettingNumber=size;
            if (mCurrentPagerFragment.hasSelectAllChecked()) {
                bettingNumber+=1;
                //表示的是有全选的按钮；
                if (mCurrentPagerFragment.hasItemChecked()) {
                    //有条目被选中；
                    cost = everyBetting * bettingNumber;
                    startAward = selectAllAward;
                    endAward = selectAllAward + itemAward;
                    startProfit = startAward - cost;
                    endProfit = endAward - cost;
                    strBettingNumber=bettingNumber+"注 , " + cost + "元" ;

                    strProfit="若中奖 , " + "奖金" + startAward + "~" + endAward + "元 , " + "盈利" + startProfit + "~" +
                            endProfit + "元";
                } else {
                    //无条目被选中；仅仅只有包选被选中；
                    cost = everyBetting * 1;
                    profit = selectAllAward - cost;

                    strBettingNumber=bettingNumber+"注 , " + cost + "元" ;
                    strProfit="若中奖 , " + "奖金" + selectAllAward + "元 , " + "盈利" + profit + "元";
                }
            } else {
                //这里表示没有全选的,
                cost = bettingNumber * everyBetting;
                profit = itemAward - cost;

                strBettingNumber=bettingNumber+"注 , " + cost + "元" ;
                strProfit="若中奖 , " + "奖金" + itemAward + "元 , " + "盈利" + profit + "元";
            }
        } else {
            //这里表示的是任选的投注方式，我们是需要根据算法，单独处理

            //这里的这个表示我们需要选择几个；
            int selectedNumber=index-4;
            if(size<selectedNumber){
                //这里表示的意思是不显示内容；
                mLlBottomTitle.setVisibility(View.INVISIBLE);
            }else{
                mLlBottomTitle.setVisibility(View.VISIBLE);
                //这里表示的是注数
                bettingNumber = BaseUtils.math2(size,selectedNumber);
                cost=bettingNumber*2;
                strBettingNumber=bettingNumber+"注 , " + cost + "元" ;
            }

          /*   switch (index) {


               case 5:
                    //这里表示任选一；
                    if(size>1 && size<3){
                        startAward=itemAward;
                        endAward=itemAward*size;
                        startProfit=startAward-cost;
                        endProfit=endAward-cost;

                        strProfit="若中奖 , " + "奖金" + startAward + "~" + endAward + "元 , " + "盈利" + startProfit + "~"
+ endProfit + "元";

                    }else if (size>=3) {
                        startAward=5;
                        endAward=15;
                        startProfit=startAward-cost;
                        endProfit=endAward-cost;

                        strProfit="若中奖 , " + "奖金" + startAward + "~" + endAward + "元 , " + "盈利" + startProfit + "~"
+ endProfit + "元";
                    }else{
                        //这里表示只选择了一个；
                        strProfit="若中奖 , 奖金5元 ，盈利3元";
                    }
                    strBettingNumber=size+"注 , " + cost + "元" ;
                    break;
                case 6:
                    break;
                case 7:
                    break;
                case 8:
                    break;
                case 9:
                    break;
                case 10:
                    break;
            }
            */
        }
        //这里我们设置值；
        mTvProfit.setText(strProfit);
        mTvProfit.requestFocus();
        mTvBettingNumber.setText(strBettingNumber);

    }

    //获得当前页面投注的注数
    public int getBettingNumber(BasePagerFragment basePagerFragment){
        if (!basePagerFragment.hasChecked()) {
            return 0;
        }

        int size = basePagerFragment.getSelectedItemIndexs().size();
        size+=basePagerFragment.hasSelectAllChecked()?1:0;

        return BaseUtils.math2(size,basePagerFragment.getAtMostSelected());
    }

    /**
     * 根据index来设置相应的规则描述；
     *
     * @param index
     */
    private void changeRules(int index) {
        if (index >= 5) {
            //mTvRadio.setVisibility(View.GONE);
            mLlNoRadioRules.setVisibility(View.VISIBLE);
            mLlRules.setVisibility(View.INVISIBLE);
        } else {
            //mTvRadio.setVisibility(View.VISIBLE);
            mLlNoRadioRules.setVisibility(View.INVISIBLE);
            mLlRules.setVisibility(View.VISIBLE);
        }

        String rule = "";
        switch (index) {
            case 0:
                rule = "所选对子开出(非豹子不分花色)中88元";
                break;
            case 1:
                rule = "开出的牌都是所选花色中90元";
                break;
            case 2:
                rule = "所选顺子开出中400元";
                break;
            case 3:
                rule = "所选花色同花顺开出即中2150元";
                break;
            case 4:
                rule = "所选豹子开出(不分花色)中6400元";
                break;
            case 5:
                rule = "至少选1个号，猜对1个号(不分花色)中5元";
                break;
            case 6:
                rule = "至少选2个号，猜对2个号(不分花色)中33元";
                break;
            case 7:
                rule = "至少选3个号，猜对3个号(不分花色)中116元";
                break;
            case 8:
                rule = "至少选4个号，猜对3个号(不分花色)中46元";
                break;
            case 9:
                rule = "至少选5个号，猜对3个号(不分花色)中22元";
                break;
            case 10:
                rule = "至少选6个号，猜对3个号(不分花色)中12元";
                break;
        }
        setRuleString(index, rule);
    }

    /**
     * 设置规则的描述，将“多少元”弄成黄色的；
     *
     * @param rule
     */
    public void setRuleString(int index, String rule) {
        int startIndex = 0;
        SpannableString spannableString = new SpannableString(rule);
        ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(0xFFfec345);
        startIndex = rule.indexOf("中") + 1;
        spannableString.setSpan(foregroundColorSpan, startIndex, rule.length(), SpannableString.SPAN_INCLUSIVE_EXCLUSIVE);

        if (index >= 5) {
            mTvRulesNoBtn.setText(spannableString);
        } else {
            mTvRules.setText(spannableString);
        }
    }

    /**
     * 根据Bar上面传递过来的索引值Index，来切换相应的Pager;
     *
     * @param position
     */
    public void setCurrentPagerIndex(int position) {

        //这里根据字符串我们来切换到相应的页面；
        // 并且我们还是需要向里面传递一个数值进去；
        if (position >= 5) {
            mViewPager.setCurrentItem(5);
            mCurrentPagerFragment = (BasePagerFragment) mMyPagerAdapter.getItem(5);
        } else {
            //大于5就设置第六个页面；
            mViewPager.setCurrentItem(position);
            mCurrentPagerFragment = (BasePagerFragment) mMyPagerAdapter.getItem(position);
        }
        //改变规则的简述
        changeRules(position);
        mCurrentPagerFragment.setIndex(position);
    }

    /**
     * 机选的按钮的逻辑是实际上是在这里实现；
     */
    public void onRandomButtonClicked() {
        //mRandomButton是那个机选的按钮；

        if (mCurrentPagerFragment.hasChecked()) {
            //表明是否有Item被选中，如果有的话，我们的逻辑就是清空，如果没有的话，我们的逻辑就是机选；
            mCurrentPagerFragment.clear();
          //  mTvRandomChoose.setText("机选");
            mBottomBar.setLeftButtonText("机选");
        } else {
            mCurrentPagerFragment.randomBetting();
           // mTvRandomChoose.setText("清空");
            mBottomBar.setLeftButtonText("清空");
        }

    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_random_choose:
                onRandomButtonClicked();
                break;
            case R.id.tv_next:
                //我们在跳转前做一个判断；
                if (mCurrentPagerFragment.hasChecked()){
                    //判断,是否构成一注；

                    int selectedItemSize = mCurrentPagerFragment.getSelectedItemIndexs().size();
                    if (mCurrentPagerFragment.hasSelectAllChecked()) {
                        selectedItemSize+=1;
                    }
                    //判断是否可以投注；
                    if (mCurrentPagerFragment.canBetting(selectedItemSize)) {
                        //这里是可以直接投注的；
                        addBetting();
                        jumpToBetConfirmActivity();
                    }else{
                        //这里表示用户选择了，但是没有达到应该选择的数量，比如任选6，但是选择了1
                        //需要弹出相应的对话框；
                        KlpkUtils.showText(getActivity(),"至少选择"+mCurrentPagerFragment.getAtMostSelected()+"张扑克");
                    }

                }else{
                    //投注区是是否有数据；
                    if(!mData.isEmpty()){
                        jumpToBetConfirmActivity();
                    }else{
                        onRandomButtonClicked();
                    }
                }
                break;
        }
    }

    private void jumpToBetConfirmActivity() {
        //这里我们将数据mData中的数据转换为下面需要的数据；
        ArrayList<String> ballNumber = new ArrayList<>();   //条目上面的title
        ArrayList<String> mode = new ArrayList<>();         //条目下面的title;
        ArrayList<String> numMoney =new ArrayList<>();      //注数和金额；
        int totalMoney=0;


        for (PokerBettingBean pokerBettingBean : mData) {

            int index = pokerBettingBean.getIndex();
            List<Integer> datas = pokerBettingBean.getDatas();
            int bettingNumber = pokerBettingBean.getBettingNumber();
            int pokerTypeIndex = index<5?index:5;

            String pokerType = "";
            //得到玩法
            String oneMode = KlpkUtils.indexType[index];
            for (Integer data : datas) {
                pokerType+=KlpkUtils.pokerType[pokerTypeIndex][data]+" ";
            }


            totalMoney+=bettingNumber*2;
            mode.add(oneMode);
            ballNumber.add(pokerType);
            numMoney.add(bettingNumber+"注"+" "+(bettingNumber*2)+"元");
        }
//        Intent intent = new Intent(getActivity(), BetConfirmActivity.class);
//        intent.putExtra("type", "klpk"); //彩种
//        intent.putExtra("totalMoney", totalMoney); //总金额
//        intent.putExtra("totalNum", mTotalBettingNum);//总注数f
//        intent.putStringArrayListExtra("ballNumber", ballNumber); //球
//        intent.putStringArrayListExtra("mode", mode); //玩法及模式
//        intent.putStringArrayListExtra("numMoney", numMoney); //注数及金额
//        startActivityForResult(intent, 0);
    }

    //这里我们来接收BetConfirmActivity里面的数据；覆盖我们的mData数据；
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode,resultCode,data);

        Intent intent = data;
        Bundle extras = intent.getExtras();
        int totalMoney = intent.getIntExtra("totalMoney", 0); //总金额
        mTotalBettingNum = intent.getIntExtra("totalNum", 0);   //总注数
        ArrayList<String> selectedNumbers = intent.getStringArrayListExtra("ballNumber"); //球
        ArrayList<String> playModes = intent.getStringArrayListExtra("mode"); //玩法
        ArrayList<String> bettingNums = intent.getStringArrayListExtra("numMoney"); //注数及金额
        //我们是需要将数据，还原回去。。
        ArrayList<PokerBettingBean> list=new ArrayList<>();

        List<String> indexType = Arrays.asList(KlpkUtils.indexType);

        if (selectedNumbers!=null && playModes!=null &&bettingNums!=null) {

            for (int i = 0; i < playModes.size(); i++) {

                PokerBettingBean pokerBettingBean = new PokerBettingBean();
                List<Integer> datas=new ArrayList<>();

                String playMode = playModes.get(i);
                String selectedNumberStr = selectedNumbers.get(i);
                String bettings = bettingNums.get(i);

                String[] selectedNumberArray = selectedNumberStr.split(" ");

                //这里表示的是poker的模式，对子，顺子，同花顺...之类的；字符串转换为索引；
                int index = indexType.indexOf(playMode);
                //我们根据这个index来拉到pokerType的第一个索引值；
                int pokerTypeIndex=index<5?index:5;
                //获取到里面的值；
                String[] strings = KlpkUtils.pokerType[pokerTypeIndex];

                List<String> pokerTypeList = Arrays.asList(strings);

                for (String s : selectedNumberArray) {

                    datas.add(pokerTypeList.indexOf(s));

                }

                String bettingNum = bettings.substring(0, bettings.indexOf("注"));

                pokerBettingBean.setIndex(index);
                pokerBettingBean.setDatas(datas);    //选中那些数字；
                pokerBettingBean.setBettingNumber(Integer.parseInt(bettingNum));
                list.add(pokerBettingBean);
            }
        }
        //这里我们是需要设置会原来的值的；
        mData=list;

        mBottomBar.setBettingNumber(mTotalBettingNum);
    }

    public void showMissingNumber(boolean showMissing) {
        //这里我们要做的一个操作就是根据showMissing来实现到底是显示还是隐藏遗漏；
        List<BasePagerFragment> data = mMyPagerAdapter.getData();
        for (BasePagerFragment basePagerFragment : data) {
            //这里是用来实现是否显示missNumber;
            basePagerFragment.showMissNumber(showMissing);
        }
    }

    public void setMissData(String missData) throws JSONException{
        mViewPager.setOffscreenPageLimit(6);
        JSONObject jsonObject = new JSONObject(missData);
        JSONObject jsonOm=jsonObject.getJSONObject("omission");
        String m0 = jsonOm.getString("m0");
        String m1 = jsonOm.getString("m1");
        String m2 = jsonOm.getString("m2");
        String m3 = jsonOm.getString("m3");
        String m4 = jsonOm.getString("m4");
        String m5 = jsonOm.getString("m4");
        //这里的话，m0封装了任选中的遗漏数据；
        String[] rxMissData = m0.split(",");
        String[] dzMissData = m1.split(",");
        String[] thMissData = m2.split(",");
        String[] szMissData = m3.split(",");
        String[] thsMissData = m4.split(",");
        String[] bzMissData = m5.split(",");

        mMyPagerAdapter.getData().get(0).setMissingData(dzMissData);
        mMyPagerAdapter.getData().get(1).setMissingData(thMissData);
        mMyPagerAdapter.getData().get(2).setMissingData(szMissData);
        mMyPagerAdapter.getData().get(3).setMissingData(thsMissData);
        mMyPagerAdapter.getData().get(4).setMissingData(bzMissData);
        mMyPagerAdapter.getData().get(5).setMissingData(rxMissData);
    }
}

